/**
 * 
 */
package ganga.gps;

import java.util.Locale;

import ganga.custodian.CustodianApplication;
import ganga.custodian.Helper;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;

/**
 * 
 * @author Apocrypha
 * 
 */
public class LocationMonitor {

	private class Listener implements LocationListener {

		@Override
		public void onLocationChanged(Location location) {
			//Helper.log("onLocationChanged");
			
		}

		@Override
		public void onProviderDisabled(String provider) {
			Helper.showToast(String.format("onProviderDisabled %s", provider));
		}

		@Override
		public void onProviderEnabled(String provider) {
			Helper.showToast(String.format("onProviderEnabled %s", provider));
		}

		@Override
		public void onStatusChanged(String provider, int status, Bundle extras) {
			Helper.showToast(String.format(Locale.US, "onStatusChanged %s %d", provider, status));
		}

	}

	private LocationManager locationManager;

	private Listener listener;

	private long minTime;

	private float minDistance;
	private Looper looper = null;

	public LocationMonitor() {
		locationManager = (LocationManager) CustodianApplication.context.getSystemService(Context.LOCATION_SERVICE);
		listener = new Listener();
	}

	public void start() {
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, listener, looper);
	}

	public void stop() {
		locationManager.removeUpdates(listener);
	}

}
